package com.zero.manage.web.components.entity.rbac;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.zero.manage.web.components.base.BaseDataEntity;
import io.gitee.zerowsh.enums.ToolEnums;
import io.gitee.zerowsh.validation.group.Insert;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.util.Set;


@Entity
@Table(name = "sys_user")
@Getter
@Setter
@ApiModel("系统用户")
public class SysUserEntity extends BaseDataEntity {
    @Column(name = "mobile")
    @ApiModelProperty("手机号")
    @NotBlank(message = "手机号必填")
    private String mobile;

    @Column(name = "nick_name")
    @ApiModelProperty("昵称")
    private String nickName;

    @Column(name = "password")
    @NotBlank(message = "密码必填", groups = {Insert.class})
    @ApiModelProperty("密码")
    //解决返回前端不序列化该字段，接收该字段传值
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;

    @Column(name = "state")
    @ApiModelProperty("用户状态")
    @Enumerated(EnumType.STRING)
    private ToolEnums.StateEnums state;
    /**
     * 登录时间
     */
    @Column(name = "login_time")
    @Ignore
    private Long loginTime;

    /**
     * 图片
     */
    @Column(name = "picture")
    private String picture;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "sys_user_role", joinColumns = @JoinColumn(name = "user_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id"))
    @ApiModelProperty("角色集合")
    @OrderBy("create_time")
    private Set<SysRoleEntity> roles;
}
